﻿using System;
using System.Windows.Forms;

namespace Mini.DownloadTool
{
    public class EventSystem : BaseHelper
    {
        private readonly FolderBrowserDialog _folderBrowserDialog;
        

        public EventSystem(FolderBrowserDialog folderBrowserDialog)
        {
            _folderBrowserDialog = folderBrowserDialog;
        }


        #region browser Folder event
        public void SaveTo_FindFolder(object sender, EventArgs e)
        {
            var drFindFolder = _folderBrowserDialog.ShowDialog();
            if (drFindFolder != DialogResult.OK) return;
            var textbox = sender as TextBox;
            if (textbox != null)
            {
                textbox.Text = _folderBrowserDialog.SelectedPath;
            }
            else
            {
                var button = sender as Button;
                if (button == null) return;
                var form = button.Parent as Form;
                if (form == null) return;
                textbox = form.Controls[TextboxNameSaveTo] as TextBox;
                if (textbox != null)
                {
                    textbox.Text = _folderBrowserDialog.SelectedPath;
                }
            }
        }
        #endregion
    }
}
